const profileService = require("../service/profile.service")

class ProfileController {
  // 获取用户信息
  async getUserMessage(ctx, next) {
    const userId = ctx.user.id
    const res = await profileService.getUserMessageByUserId(userId)
    ctx.body = {
      status: 200,
      data: {
        ...res,
        name: ctx.user.name
      }
    }
  }
  // 设置用户电话
  async addUserPhone(ctx, next) {
    const { phone } = ctx.request.body
    const userId = ctx.user.id
    await profileService.updateUserPhone(phone, userId)
    ctx.body = {
      status: 201,
      message: '设置电话成功'
    }
  }
  // 设置用户邮箱
  async addUserEmail(ctx, next) {
    const { email } = ctx.request.body
    const userId = ctx.user.id
    await profileService.updateUserEmail(email, userId)
    ctx.body = {
      status: 201,
      message: '设置邮箱成功'
    }
  }
  // 设置用户邮箱
  async addUserIntroduce(ctx, next) {
    const { introduce } = ctx.request.body
    const userId = ctx.user.id
    await profileService.updateUserIntroduce(introduce, userId)
    ctx.body = {
      status: 201,
      message: '设置个人介绍成功'
    }
  }
}

module.exports = new ProfileController()